package com.ruoyi.purchase.controller;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.purchase.domain.ZsPurchaseProcess;
import com.ruoyi.purchase.service.IZsPurchaseProcessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * purchaseController
 * 
 * @author ruoyi
 * @date 2022-03-17
 */
@RestController
@RequestMapping("/purchase/process")
public class ZsPurchaseProcessController extends BaseController
{
    @Autowired
    private IZsPurchaseProcessService zsPurchaseProcessService;

    /**
     * 查询purchase列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:process:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZsPurchaseProcess zsPurchaseProcess)
    {
        startPage();

        List<ZsPurchaseProcess> list = zsPurchaseProcessService.selectZsPurchaseProcessList(zsPurchaseProcess);
        return getDataTable(list);
    }

    /**
     * 导出purchase列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:process:export')")
    @Log(title = "purchase", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZsPurchaseProcess zsPurchaseProcess)
    {
        List<ZsPurchaseProcess> list = zsPurchaseProcessService.selectZsPurchaseProcessList(zsPurchaseProcess);
        ExcelUtil<ZsPurchaseProcess> util = new ExcelUtil<ZsPurchaseProcess>(ZsPurchaseProcess.class);
        util.exportExcel(response, list, "purchase数据");
    }

    /**
     * 获取purchase详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:process:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zsPurchaseProcessService.selectZsPurchaseProcessById(id));
    }

    /**
     * 新增purchase
     */
    @PreAuthorize("@ss.hasPermi('purchase:process:add')")
    @Log(title = "purchase", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZsPurchaseProcess zsPurchaseProcess)
    {
        BigDecimal purchasePrice = zsPurchaseProcess.getPurchasePrice();
        Long purchaseCount = zsPurchaseProcess.getPurchaseCount();
        if (purchaseCount!=null){
            BigDecimal purchaseCount1=new BigDecimal(purchaseCount);
            BigDecimal total=purchasePrice.multiply(purchaseCount1);
            zsPurchaseProcess.setPurchaseMoney(total);}
        return toAjax(zsPurchaseProcessService.insertZsPurchaseProcess(zsPurchaseProcess));
    }

    /**
     * 修改purchase
     */
    @PreAuthorize("@ss.hasPermi('purchase:process:edit')")
    @Log(title = "purchase", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZsPurchaseProcess zsPurchaseProcess)
    {
        return toAjax(zsPurchaseProcessService.updateZsPurchaseProcess(zsPurchaseProcess));
    }

    /**
     * 删除purchase
     */
    @PreAuthorize("@ss.hasPermi('purchase:process:remove')")
    @Log(title = "purchase", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zsPurchaseProcessService.deleteZsPurchaseProcessByIds(ids));
    }
}
